<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>登陆日志</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../lib/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
		<!--查询代码  开始-->
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="" id="searchFrm">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">登陆名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="loginnam" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">登陆IP</label>
                            <div class="layui-input-inline">
                                <input type="text" name="loginip" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">开始时间</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly="readonly" name="startTime" id="startTime" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">结束时间</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly="readonly" name="endTime" id="endTime" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="button" class="layui-btn" lay-submit  lay-filter="data-search-btn"><i class="layui-icon">&#xe615;</i> 搜 索</button>
                            <button type="button" class="layui-btn layui-btn-warm" onclick="javascript:$('#searchFrm')[0].reset()" ><i class="layui-icon">&#xe669;</i> 清 空</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
		<!--查询结束  开始-->
	<!--数据表格  开始-->
        <script type="text/html" id="logInfoTableToolbar">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="deletes"> 批量删除 </button>
            </div>
        </script>

        <table class="layui-hide" id="logInfoTableId" lay-filter="logInfoTableFilter"></table>

        <script type="text/html" id="logInfoTableTemplet">
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>
	    <!--数据表格  结束-->
	
    </div>
</div>
<script src="../../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="../../../lib/layui/layui.js" charset="utf-8"></script>
<script src="../../../js/lay-config.js?v=2.0.0" charset="utf-8"></script>
<script src="../../../lib/jquery-3.4.1/jquery.cookie.min.js" charset="utf-8"></script>
<script src="../../../lib/common/common.js" charset="utf-8"></script>

<script>
    layui.use(['form', 'table','laydate'], function () {
        var $ = layui.jquery,
            form = layui.form,
			laydate=layui.laydate,
            table = layui.table;

		//绑定时间选择器
		laydate.render({
			elem:'#startTime',
			type:'datetime',
			theme:'molv'
		});
		laydate.render({
			elem:'#endTime',
			type:'datetime',
			theme:'molv'
		});
        //渲染数据表格
       var tableIns = table.render({
            elem: '#logInfoTableId',
            url: api+'logInfo/loadAllLogInfo',
            toolbar: '#logInfoTableToolbar',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {type: "checkbox",  fixed: "left",align:"center"},
                {field: 'id',  title: 'ID', align:"center"},
                {field: 'loginname',  title: '登陆名称'},
                {field: 'loginip',  title: '登陆IP'},
                {field: 'logintime',  title: '登陆时间',align:"center"},
                {title: '操作',  templet: '#logInfoTableTemplet', fixed: "right", align: "center"}
            ]],
            page: true
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var params=$("#searchFrm").serialize();
            table.reload('logInfoTableId', {
                page: {
                    curr: 1
                }
                , url: api+'logInfo/loadAllLogInfo?'+params
            }, 'data');
            return false;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(logInfoTableFilter)', function (obj) {
            if (obj.event === 'deletes') {  // 监听删除操作
               batchDeleteDataByIds();
            }
        });
		
        table.on('tool(logInfoTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'delete') {
               deleteDataById(obj);
            }
        });
		
		
		//根据ID删除
		function deleteDataById(obj){
			 var data = obj.data;
			layer.confirm('真的删除【'+data.loginname+'】这行数据么', function (index) {
				$.post(api+"logInfo/deleteLogInfo",{id:data.id},function(res){
					if(res.code==1){
						obj.del();
					} 
					layer.msg(res.msg);
					layer.close(index);
				})
			});
		}
		
		//批量删除
		function batchDeleteDataByIds(){
			layer.confirm('真的删除这些数据么', function (index) {
				var checkStatus = table.checkStatus('logInfoTableId');
				var data = checkStatus.data;
				var params=""
				$.each(data,function(i,item){
					if(i==0){
						params+="?ids="+item.id;
					}else{
						params+="&ids="+item.id;
					}
				});
				$.post(api+"logInfo/batchDeleteLogInfo"+params,function(res){
					if(res.code==1){
						tableIns.reload();
					} 
					layer.msg(res.msg);
					layer.close(index);
				})
			});
		}
    });
</script>
<script>

</script>

</body>
</html>